package com.atu.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletResponse;


public class ResponseServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        //方式一：
//        // 设置服务器字符集为 UTF-8
//        response.setCharacterEncoding("UTF-8");
//        // 通过响应头，设置浏览器也使用 UTF-8 字符集
//        response.setHeader("Content-Type", "text/html; charset=UTF-8");

        //方式二：
        //它会同时设置服务器和客户端都使用 UTF-8 字符集，还设置了响应头
        // 此方法一定要在获取流对象之前调用才有效
        response.setContentType("text/html; charset=UTF-8");
        //往客户端（浏览器）中回传数据
        PrintWriter responseWriter = response.getWriter();
        responseWriter.write("hello javaweb!");
        responseWriter.write("刘明福很帅!");
    }
}
